package com.atguigu.flink.day03;

import com.atguigu.flink.bean.WaterSensor;
import com.atguigu.flink.func.MyMapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2024/8/12
 * 该案例演示了转换算子-filter
 * 需求：将数据流中传感器id为sensor_1的数据过滤出来
 */
public class Flink10_Transform_Filter {
    public static void main(String[] args) throws Exception {
        //TODO 1.指定流处理环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        //TODO 2.准备数据
        DataStreamSource<WaterSensor> stream = env.fromElements(
                new WaterSensor("sensor_1", 1L, 1),
                new WaterSensor("sensor_2", 2L, 2)
        );
        //TODO 3.过滤
        SingleOutputStreamOperator<WaterSensor> ds = stream.filter(
                ws -> "sensor_1".equals(ws.id)
        );

        //TODO 4.打印
        ds.print();

        //TODO 5.提交作业
        env.execute();


    }
}
